﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class Month_MonthPlanResolveAddForTip : System.Web.UI.Page
{
    MonthPlanDetailManager dllMonthPlanDetailManager = new MonthPlanDetailManager();
    IBussinessLogic dllMonthPlan = new MonthPlanManager();
    Authentication dllAuthentication = new Authentication();
    DataTable _MonthPlanTable = new DataTable();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    BLL.MonthPlanManager dllMonthPlanManager = new MonthPlanManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();

        if (!IsPostBack)
        {
            bindMonthPlanGridView();

        }

    }

    /// <summary>
    /// 绑定空记录表头GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    void bindMonthPlan()
    {
        DataTable _MonthPlan = createDataTable();
        DataRow dr = _MonthPlan.NewRow();
        _MonthPlan.Rows.Add(dr);
        this.gdvMonthPlanResolve.DataSource = _MonthPlan;
        this.gdvMonthPlanResolve.DataBind();
        //隐藏首行，只保留表头
        this.gdvMonthPlanResolve.Rows[0].Visible = false;
        for (int i = 0; i < this.gdvMonthPlanResolve.Rows.Count; i++)
        {
            if (this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "&amp;nbsp;" || this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "&nbsp;" || this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "")
            {
                this.gdvMonthPlanResolve.Rows[i].Cells[10].Text = "";
            }
        }
    }

    /// <summary>
    /// 绑定月分解GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    void bindMonthPlanGridView()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsString("_MonthPlanId");
        DataTable _MonthPlan = dllMonthPlanDetailManager.get(MonthPlanDetailManager.field.MonthPlanId.ToString(), _value);

        DataView dv = new DataView(_MonthPlan);
        dv.Sort = "MonthDetailPlanId";
        this.gdvMonthPlanResolve.DataSource = dv;
        this.gdvMonthPlanResolve.DataBind();
        if (this.gdvMonthPlanResolve.Rows.Count > 0)
        {
            //隐藏首行，只保留表头 
            int isManager = dllAuthentication.IsManager(objUserInfo.UserName);

            for (int i = 0; i < this.gdvMonthPlanResolve.Rows.Count; i++)
            {
                if (this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "&amp;nbsp;" || this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "&nbsp;" || this.gdvMonthPlanResolve.Rows[i].Cells[10].Text == "")
                {
                    this.gdvMonthPlanResolve.Rows[i].Cells[10].Text = "";
                }
            }
            this.gdvMonthPlanResolve.Visible = true;
            this.lbltip.Visible = false;
        }
        else
        {
            this.gdvMonthPlanResolve.Visible = false;
            this.lbltip.Visible = true;
        }
    }


    /// <summary>
    /// 绑定月分解计划GridView
    /// </summary>
    void bindGridViewMonthResolve(string _MonthPlanId)
    {
        object[] _value = new object[1];
        _value[0] = _MonthPlanId;
        DataTable _MonthResolve = dllMonthPlanDetailManager.get(MonthPlanDetailManager.field.MonthPlanId.ToString(), _value);
        this.gdvMonthPlanResolve.DataSource = _MonthResolve;
        this.gdvMonthPlanResolve.DataBind();

        for (int i = 0; i < this.gdvMonthPlanResolve.Rows.Count; i++)
        {
            wrapByComma(this.gdvMonthPlanResolve, i, 5);
            wrapByComma(this.gdvMonthPlanResolve, i, 6);

            this.gdvMonthPlanResolve.Rows[i].Cells[8].Text = this.gdvMonthPlanResolve.Rows[i].Cells[8].Text.Replace("&", "");
            this.gdvMonthPlanResolve.Rows[i].Cells[8].Text = this.gdvMonthPlanResolve.Rows[i].Cells[8].Text.Replace("nbsp;", "");
            this.gdvMonthPlanResolve.Rows[i].Cells[8].Text = this.gdvMonthPlanResolve.Rows[i].Cells[8].Text.Replace("&amp;nbsp;", "");

        }
    }

    /// <summary>
    /// 创建空DataTable用于绑定GridView
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-16</date>
    DataTable createDataTable()
    {
        DataTable _dataTable = new DataTable();
        _dataTable.Columns.Add("MonthDetailPlanId");
        _dataTable.Columns.Add("StartTime");
        _dataTable.Columns.Add("CompleteTime");
        _dataTable.Columns.Add("WorkItem");
        _dataTable.Columns.Add("MasterDepartment");
        _dataTable.Columns.Add("MasterPeople");
        _dataTable.Columns.Add("SlaveDepartment");
        _dataTable.Columns.Add("SlaveDepartmentDuty");
        _dataTable.Columns.Add("EvaluatePeople");
        _dataTable.Columns.Add("Remart");
        _dataTable.Columns.Add("Id");
        _dataTable.Columns.Add("MonthPlanId");
        _dataTable.Columns.Add("Sponsor");
        return _dataTable;
    }







    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }

}